package com.fengmi.service.impl;

import com.fengmi.entity.MallGoodsCat;
import com.fengmi.mapper.GoodsCategoryMapper;
import com.fengmi.service.GoodsCategoryService;
import com.fengmi.vo.CascadeVO;
import com.fengmi.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class GoodsCategoryServiceImpl implements GoodsCategoryService {

    @Autowired
    private GoodsCategoryMapper categoryMapper;

    @Override
    public ResultVO selectAllCategoryCascade() {

        List<CascadeVO> cascadeVOList = categoryMapper.findAllFirstLevelCatAndChildren();

        return new ResultVO(true,"success", cascadeVOList);
    }

    @Override
    public ResultVO selectCatByParentId(String pid) {
        if (StringUtils.isEmpty(pid)){
            return new ResultVO(false,"参数不合法");
        }
        List<MallGoodsCat> goodsCatList = categoryMapper.findCatByPid(pid);

        if (goodsCatList == null || goodsCatList.size() == 0){
            return new ResultVO(false,"查询错误");
        }
        return new ResultVO(true,"success",goodsCatList);
    }

    @Override
    public ResultVO updateCategoryById(MallGoodsCat mallGoodsCat) {
        if (mallGoodsCat == null){
            return new ResultVO(false,"参数不合法");
        }
        int i = categoryMapper.updateGoodsCategoryInfo(mallGoodsCat);

        return new ResultVO(i==1?true:false,i==1?"修改商品分类信息成功":"修改商品分类信息失败");
    }
}
